package com.banzhi.shop.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.banzhi.shop.activity.CommodityDetailsActivity;
import com.banzhi.shop.activity.ViewPagerActivity;
import com.banzhi.shop.view.FlyBanner;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by HT on 2017/5/2.
 */
public class ViewPagerAdapter extends PagerAdapter{
    // 是否是网络图片
    // private boolean mIsImageUrl = false;
    private Context context;
    private List<ImageView> list = new ArrayList<ImageView>();

    public ViewPagerAdapter(List<ImageView> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(list.get(position ));
    }

    @Override
    public Object instantiateItem(ViewGroup container,  int position) {
        ImageView imageView = list.get(position);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setTag(position);
        container.addView(imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

              /*  int position=(Integer) v.getTag();
                Intent intent = new Intent(context, ViewPagerActivity.class);
                intent.putExtra("images", list);
                intent.putExtra("position", position);
                context.startActivity(intent);*/

         /*        if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(toRealPosition(position));
                }*/
            }
        });
        return imageView;
    }

/*    //本地图片资源
    private List<Integer> mImages;
    private int toRealPosition(int position) {
        int realPosition;
        if (mIsImageUrl) {
            realPosition = (position - 1) % list.size();
            if (realPosition < 0)
                realPosition += list.size();
        } else {
            realPosition = (position - 1) % mImages.size();

            if (realPosition < 0)
                realPosition += mImages.size();
        }

        return realPosition;
    }*/
/*    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }*/
}
